<?php
session_start();
//session_register('login_state');
//$_SESSION['login_state'] ;
//===========================================================
$path = '../';
include($path."common.php");
include($path."prod_fun.php");
//=========================================================== 
$pageout = "ord_login.php" ; 
if($_SESSION['login_state'] <> "S" and $_SESSION['login_state'] <> "O"){
	gotopage($pageout) ;
} 
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../css/cart.css" />
<script language="javascript" type="text/javascript" src="../js/jquery.js"></script>
<script language="javascript">
$.ajaxSetup({
  cache: false
});

function ord_check(_time,_gwsr,_amount,_spcheck,_sum){
if(_sum != ''){

$.get("ord_check.php?time="+_time+"&gwsr="+_gwsr+"&amount="+_amount+"&spcheck="+_spcheck+"&sum="+_sum,function(msg){
alert(msg) ;
});

}
else{
alert("請輸入商店檢查碼 !") ;
}

}
</script>
<?
$nowpage = $_GET['nowpage'] ;

echo "<form method=post id=frm name=frm action=\"ord_act.php?nowpage=$nowpage\">" ;
echo "<table width=100% border=1 align=center cellspacing=0  cellpadding=0>" ;
//===========================================================
$id = $_GET['oid'] ;
//===========================================================
//訂單主要資訊
$sql_edit = "select * from  kart_order where order_id = '$id' order by order_id" ;
$result_edit = mysql_query($sql_edit);
$row_edit=mysql_fetch_object($result_edit);
$ordno = $row_edit->order_id;						//訂單編號
$ord_type = $row_edit->order_type;						//付費方式
$ord_price = $row_edit->order_price;						//訂單金額
$ord_date = $row_edit->order_date;						//訂單日期
$ord_time = $row_edit->order_time;						//訂單時間
$ord_state = $row_edit->order_state;						//訂單狀態
$ord_invoice = $row_edit->order_invoice;						//訂單發票抬頭
$ord_invoiceno = $row_edit->order_invoiceno;						//訂單統一編號
$ord_auth = $row_edit->order_auth;						//授權碼
$ord_gwsr = $row_edit->order_gwsr;						//授權單號
$ord_spcheck = $row_edit->order_spcheck;						//商店驗證碼
$ord_stage = $row_edit->order_stage;						//分期期數



switch($ord_type){
case "1_1" :
$type = "ATM轉帳" ;    
break;
case "1_2" :
$type = "銀行匯款" ;    
break;
case "1_3" :
$type = "WebAtm" ;    
break;
case "1_4" :
$type = "貨到付款" ;    
break;
case "3" :
$type = "一次刷卡" ;    
break;
case "4_1" :
$type = "分期付款(3期)" ;    
break;
case "4_2" :
$type = "分期付款(6期)" ;    
break;
case "4_3" :
$type = "分期付款(12期)" ;    
break;
case "4_4" :
$type = "分期付款(24期)" ;    
break;
}

switch($ord_state){
case "S" :
$state = "已付費，已確認送貨" ;    
break;
case "Y" :
$state = "已付費，尚未送貨" ;    
break;
case "N" :
$state = "尚未付費" ;    
break;
}
//===========================================================
//購買人主要資訊
$sql_shopper = "select * from  order_shopper where order_id = '$id' order by order_id" ;
$result_shopper = mysql_query($sql_shopper);
$row_shopper=mysql_fetch_object($result_shopper);
$shopper_name = $row_shopper->shopper_name;						//購買人姓名
$shopper_tel = $row_shopper->shopper_tel;						//購買人電話
$shopper_phone = $row_shopper->shopper_cellphone;					//購買人手機
$shopper_zip = $row_shopper->shopper_zip;						//購買人郵遞區號
$shopper_address = $row_shopper->shopper_address;						//購買人地址
$shopper_mail = $row_shopper->shopper_mail;						//購買人信箱
//===========================================================
//收貨人主要資訊
$sql_consignee = "select * from  order_consignee where order_id = '$id' order by order_id" ;
$result_consignee = mysql_query($sql_consignee);
$row_consignee=mysql_fetch_object($result_consignee);
$consignee_name = $row_consignee->consignee_name;						//收貨人姓名
$consignee_tel = $row_consignee->consignee_tel;						//收貨人電話
$consignee_phone = $row_consignee->consignee_cellphone;					//收貨人手機
$consignee_zip = $row_consignee->consignee_zip;						//收貨人郵遞區號
$consignee_address = $row_consignee->consignee_address;						//收貨人地址
$consignee_mail = $row_consignee->consignee_mail;						//收貨人信箱
//===========================================================
echo "<tr><td colspan=2 align=left>" ;
echo "<table width=100% border=0 align=center cellspacing=1 cellpadding=1>" ;
echo "<tr>" ;
echo "<td align=right width=10%>訂單編號:</td>" ;
echo "<td align=left><input name=od_no readonly type=text size=20 value='$ordno'></td>" ;
echo "</tr>" ;
//echo "<tr>" ;
//echo "<td align=right>授權碼:</td>" ;
//echo "<td align=left><input name=od[] readonly type=text size=20 value='$ord_auth'></td>" ;
//echo "</tr>" ;
if($ord_gwsr){
echo "<tr>" ;
echo "<td align=right>授權單號:</td>" ;
echo "<td align=left><input name=od[] readonly type=text size=20 value='$ord_gwsr'></td>" ;
echo "</tr>" ;
}
//echo "<tr>" ;
//echo "<td align=right>商店驗證碼:</td>" ;
//echo "<td align=left><input name=od[] readonly type=text size=20 value='$ord_spcheck'></td>" ;
//echo "</tr>" ;
echo "<tr>" ;
echo "<td align=right>發票抬頭:</td>" ;
echo "<td align=left><input name=od[] readonly type=text size=20 value='$ord_invoice'></td>" ;
echo "</tr>" ;
echo "<tr>" ;
echo "<td align=right>統一編號:</td>" ;
echo "<td align=left><input name=od[] readonly type=text size=20 value='$ord_invoiceno'></td>" ;
echo "</tr>" ;
echo "<tr>" ;
echo "<td align=right>分期期數:</td>" ;
echo "<td align=left><input name=od[] readonly type=text size=20 value='$ord_stage'></td>" ;
echo "</tr>" ;
echo "<tr>" ;
echo "<td align=right>交易金額:</td>" ;
echo "<td align=left><input name=od[] readonly type=text size=20 value='$ord_price'></td>" ;
echo "</tr>" ;
echo "<tr>" ;
echo "<td align=right>付款方式:</td>" ;
echo "<td align=left><input name=od[] readonly type=text size=20 value='$type'></td>" ;
echo "</tr>" ;
echo "<tr>" ;
echo "<td align=right>訂單狀態:</td>" ;
echo "<td align=left><select name=od_st>" ;
echo "<option value='$ord_state'>".$state."</option>" ;
echo "<option value='S'>"."已付費，已確認送貨"."</option>" ;
echo "<option value='Y'>"."已付費，尚未送貨"."</option>" ;
echo "<option value='N'>"."尚未付費"."</option>" ;
echo "</select>" ;
echo "<input name=action  type=submit value='修改'>" ;
echo "</td>" ;
echo "</tr>" ;
if($ord_gwsr){
echo "<tr>" ;
echo "<td align=right>交易驗證:</td>" ;
echo "<td align=left><input id=chk name=od[] type=text size=20 value=''>" ;
echo "<input name=ck_button type=button value='檢查' onclick=\"ord_check('$ord_time','$ord_gwsr','$ord_price','$ord_spcheck',chk.value);\">" ;
echo "<a href=\"https://ecpay.com.tw/\" target=_new>連線至綠界</a>" ;
echo "</td>" ;
echo "</tr>" ;
}
echo "</table>" ;
echo "</td></tr>" ;
//===========================================================
//訂單商品資訊
echo "<tr><td colspan=2>" ;
echo "<table width=100% border=0 align=center cellspacing=1 cellpadding=1>" ;
echo "<tr><td class=t_color><h3>商品清單</h3></td></tr>" ;
echo "<tr>" ;
echo "<td align=center>商品名稱</td>" ;
echo "<td align=center width=10%>數量</td>" ;
echo "<td align=center width=10%>單價</td>" ;
echo "<td align=center width=10%>小計</td>" ;
echo "<td align=center width=10%>庫存</td>" ;
echo "</tr>" ;
$sql_item = "select * from  order_item where order_id = '$id' order by order_id" ;
$result_item = mysql_query($sql_item);
while($row_item=mysql_fetch_object($result_item)){
$item_no = $row_item->item_id;							//商品編號
$item_amount = $row_item->item_amount;						//商品購買數量

$sql_pd = "select * from  product where id = '$item_no' " ;
$result_pd = mysql_query($sql_pd);
$row_pd = mysql_fetch_object($result_pd);
$pd_name = $row_pd->name;  //商品名稱
$pd_count = $row_pd->pd_count; //商品庫存
$pd_price1 = $row_pd->price_1; //建議售價
$pd_price2 = $row_pd->price_2; //網路售價

$pd_amount = $item_amount * $pd_price2 ;

echo "<tr>" ;
echo "<td><input name=pdname[] readonly type=text size=100 value='$pd_name'></td>" ;
echo "<td><input name=pdcount[] readonly type=text size=10 value='$item_amount'></td>" ;
echo "<td><input name=pdprice[] readonly type=text size=10 value='$pd_price2'></td>" ;
echo "<td><input name=pdsum[] readonly type=text size=10 value='$pd_amount'></td>" ;
echo "<td><input name=pdstock[] readonly type=text size=10 value='$pd_count'></td>" ;
echo "</tr>" ;
}
echo "</table>" ;
echo "</td></tr>" ;
//===========================================================
echo "<tr>" ;
echo "<td align=center>" ;
//購買人資訊
echo "<table width=100% border=0 align=center cellspacing=1 cellpadding=1>" ;
echo "<tr><td colspan=2 class=t_color><h3>付款人資訊</h3></td></tr>" ;

echo "<tr>" ;
echo "<td align=right width=15%>姓名:</td>" ;
echo "<td align=left><input name=shopper_name readonly type=text size=20 value='$shopper_name'></td>" ;
echo "</tr>" ;

echo "<tr>" ;
echo "<td align=right>市話:</td>" ;
echo "<td align=left><input name=shopper_tel readonly type=text size=12 value='$shopper_tel'></td>" ;
echo "</tr>" ;

echo "<tr>" ;
echo "<td align=right>手機:</td>" ;
echo "<td align=left><input name=shopper_phone readonly type=text size=12 value='$shopper_phone'></td>" ;
echo "</tr>" ;

echo "<tr>" ;
echo "<td align=right>電子郵件:</td>" ;
echo "<td align=left><input name=shopper_mail readonly type=text size=50 value='$shopper_mail'></td>" ;
echo "</tr>" ;

echo "<tr>" ;
echo "<td align=right>郵遞區號:</td>" ;
echo "<td align=left><input name=shopper_zip readonly type=text size=5 value='$shopper_zip'></td>" ;
echo "</tr>" ;

echo "<tr>" ;
echo "<td align=right>地址:</td>" ;
echo "<td align=left><input name=shopper_address readonly type=text size=50 value='$shopper_address'></td>" ;
echo "</tr>" ;
echo "</table>" ;

echo "</td>" ;

//-----------------------------------------------------------------------------------------
//收貨人資訊
echo "<td align=center>" ;

echo "<table width=100% border=0 align=center cellspacing=1 cellpadding=1>" ;
echo "<tr><td colspan=2 class=t_color><h3>收件人資訊</h3></td></tr>" ;
echo "<tr>" ;
echo "<td align=right width=15%>姓名:</td>" ;
echo "<td align=left><input name=consignee_name readonly type=text size=20 value='$consignee_name'></td>" ;
echo "</tr>" ;

echo "<tr>" ;
echo "<td align=right>市話:</td>" ;
echo "<td align=left><input name=consignee_tel readonly type=text size=12 value='$consignee_tel'></td>" ;
echo "</tr>" ;

echo "<tr>" ;
echo "<td align=right>手機:</td>" ;
echo "<td align=left><input name=consignee_phone readonly type=text size=12 value='$consignee_phone'></td>" ;
echo "</tr>" ;

echo "<tr>" ;
echo "<td align=right>電子郵件:</td>" ;
echo "<td align=left><input name=consignee_mail readonly type=text size=50 value='$consignee_mail'></td>" ;
echo "</tr>" ;

echo "<tr>" ;
echo "<td align=right>郵遞區號:</td>" ;
echo "<td align=left><input name=consignee_zip readonly type=text size=5 value='$consignee_zip'></td>" ;
echo "</tr>" ;

echo "<tr>" ;
echo "<td align=right>地址:</td>" ;
echo "<td align=left><input name=consignee_address readonly type=text size=50 value='$consignee_address'></td>" ;
echo "</tr>" ;
echo "</table>" ;


echo "</td>" ;
echo "</tr>" ;
//===========================================================
echo "<tr>" ;
echo "<td colspan=2>" ;
echo "<table width=100% border=0 align=center cellspacing=1 cellpadding=1>" ;
echo "<tr>" ;



echo "<td colspan=2 align=center><input name=action type=submit value='返回清單'></td>" ;
echo "</tr>" ;
echo "</table>" ;
echo "</td>" ;
echo "</tr>" ;
//===========================================================
echo "</table>" ;
//===========================================================
echo "</form>" ;
?>